package com.zz.springboot.controller;

import com.zz.springboot.dto.MaxMoneyParamDto;
import com.zz.springboot.req.vo.MaxMoneyVo;
import com.zz.springboot.resp.RespTemplate;
import com.zz.springboot.service.SetParamService;
import lombok.extern.slf4j.Slf4j;
import org.apache.shiro.SecurityUtils;
import org.apache.shiro.authz.annotation.Logical;
import org.apache.shiro.authz.annotation.RequiresRoles;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@Slf4j
public class SetParamController {

    @Autowired
    private SetParamService setParamService;
    @RequiresRoles(value = {"member", "admin"},logical = Logical.OR)
    @RequestMapping("/setEatTotal")
    public RespTemplate setEatTotal(MaxMoneyVo maxMoneyVo) {
        // 封装参数
        MaxMoneyParamDto maxMoneyParam = new MaxMoneyParamDto();
        maxMoneyParam.setAomenMaxValue(maxMoneyVo.getAomenMaxValue());
        maxMoneyParam.setXianggangMaxValue(maxMoneyVo.getXianggangMaxValue());
        maxMoneyParam.setOperator((String)SecurityUtils.getSubject().getSession().getAttribute("username"));

        setParamService.setMaxMoneyParam(maxMoneyParam);

        return RespTemplate.success();
    }
}
